

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Canvas implements Printable {
	private String path = "";
	
	public void setImagePath(String path){
		this.path = path;
	}
	
	public int print(Graphics g, PageFormat pf, int page)
	      throws PrinterException {
		if(page>=1) return Printable.NO_SUCH_PAGE;
		Graphics2D g2 = (Graphics2D)g;
		g2.translate(pf.getImageableX(), 0);

		try {
			BufferedImage img;
			img = ImageIO.read(new File(path));
			g2.drawImage(img, 0, 0, null);
		} catch (IOException e) {
			e.printStackTrace();
		}		
		return Printable.PAGE_EXISTS;
	}
	 
}
